package com.diligent.cloud.sfc.resources.impl;

import com.canny.commons.model.ObjectResult;
import com.diligent.cloud.sfc.model.params.ConsumablesOutOfWarehouseParams;
import com.diligent.cloud.sfc.model.params.FinishedGoodsOutOfWarehouseParams;
import com.diligent.cloud.sfc.model.params.MatStorageParams;
import com.diligent.cloud.sfc.resources.WipResource;
import com.diligent.cloud.sfc.service.WipService;
import com.diligent.cloud.web.resource.impl.AbstractActionResourceImpl;
import com.diligent.foundation.web.action.DiligentActionFunction;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

/**
 * WipResource class
 *
 * @author xf107278
 * @date 4/7/2020
 */
@RestController
public class WipResourceImpl extends AbstractActionResourceImpl implements WipResource {

    private WipService wipService;

    public WipResourceImpl(WipService wipService) {
        this.wipService = wipService;
        init();
    }




    @Override
    public ResponseEntity<ObjectResult> selectById(Long id) {
        return null;
    }

    private void init() {
        DiligentActionFunction diligentActionFunction = (var1, var2, var3) -> {
            MatStorageParams var31 = (MatStorageParams) var3;

            return wipService.addMatStorage(var31.getGuideMaster(), var31.getPrincipal()).getBody();
        };

        super.registerAction(HttpMethod.POST.toString(), "addMatStorage", MatStorageParams.class,
                diligentActionFunction);


        super.registerAction(HttpMethod.POST.toString(), "updateMatStorage", FinishedGoodsOutOfWarehouseParams.class,
                (var1, var2, var3) -> {
                    return wipService.updateMatStorage(var3).getBody();
                });

        super.registerAction(HttpMethod.POST.toString(), "updateConsumeStorage", ConsumablesOutOfWarehouseParams.class,
                (var1, var2, var3) -> {
                    return wipService.updateConsumeStorage(var3).getBody();
                });
    }


    @Override
    public ResponseEntity<ObjectResult> getInventoryByMatCodeAndCwocCode(String matCode, String cwocCode,
                                                                         String batchCode, Long systemId) {
        return wipService.getInventoryByMatCodeAndCwocCode(matCode, cwocCode, batchCode, systemId);
    }
}
